new Vue({
    el: '#app',
    data(){
        return {
            bills:[],
            activeIndex: '3',
            searchByCondition:{}, // 条件查询
            pickerOptions: {
                disabledDate(time) {
                  return time.getTime() > Date.now();
                },
                shortcuts: [{
                  text: '今天',
                  onClick(picker) {
                    picker.$emit('pick', new Date());
                  }
                }, {
                  text: '昨天',
                  onClick(picker) {
                    const date = new Date();
                    date.setTime(date.getTime() - 3600 * 1000 * 24);
                    picker.$emit('pick', date);
                  }
                }, {
                  text: '一周前',
                  onClick(picker) {
                    const date = new Date();
                    date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                    picker.$emit('pick', date);
                  }
                }]
              }, // 日期快捷
            doctor:{},// 医生信息
            dialogVisiblePatient:false, // 医生信息显示
            registration:{}, // 挂号单信息
            dialogVisibleRegistration:false, // 挂号单信息显示
        }
    },
    methods: {
        // 关闭
        handleClose(done) {
            this.$confirm('确认关闭？')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          },
        // 导航
        handleSelect(key, keyPath) {
            if(key==2){
                 location.href="doctor.html"
            }else if(key==1){
                location.href="patient.html"
            }else if(key==4){
                location.href="registration.html"
            }
           
          },
          // 根据患者id查询账单
          getBillByPatientId(id){

            let _this = this;
            axios(
                {
                    method:"GET",
                    url: "http://localhost/bills/get/patientid/"+id,
                }
            ).then(function(resp){
                console.log(resp.data);
                _this.bills=resp.data.data;
                _this.bills.forEach(item=>{
                    item.time=_this.toDate( item.time)
                })
            })
        },
       
        // 条件查询
        getByCondition(){
        let _this = this;
        console.log(_this.searchByCondition)
        axios(
            {
                method:"POST",
                url: "http://localhost/bills/get/conditon",
                data:_this.searchByCondition
            }
        ).then(function(resp){
            console.log(resp.data);
            _this.bills=resp.data.data;
            _this.bills.forEach(item=>{
                item.time=_this.toDate( item.time)
            })
        })
         },

         // 根据医生id查询医生信息
         getDoctorById(id){
            this.dialogVisiblePatient=true
            console.log(id)
            let _this = this;
            axios(
                {
                    method:"GET",
                    url: "http://localhost/doctors/get/id/"+id,
                }
            ).then(function(resp){
                console.log(resp.data);
                _this.doctor=resp.data.data;
            })
         },


         // 根据挂号单id查询挂号单信息
         getRegistrationById(id){
            this.dialogVisibleRegistration=true;
            console.log(id)
            let _this = this;
            axios(
                {
                    method:"GET",
                    url: "http://localhost/registrations/get/id/"+id,
                }
            ).then(function(resp){
                console.log(resp.data);
                _this.registration=resp.data.data;
                _this.registration.time=_this.toDate(_this.registration.time)
            })
         },

        // 获得所有账单
        getAllBills(){
            let _this = this;
            axios(
                {
                    method:"GET",
                    url: "http://localhost/bills/get/all/",
                }
            ).then(function(resp){
                console.log(resp.data);
                _this.searchByCondition={}
                _this.bills=resp.data.data;
                _this.bills.forEach(item=>{
                    item.time=_this.toDate( item.time)
                })
            })
        },
        // 时间戳转换
        toDate(time){
            var date= new Date(time)
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
            var D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
            let strDate = Y+M+D;
            return strDate;
        },
      },



      mounted(){
        var param = location.search;
        if(param==""){
            this.getAllBills();
        }
        console.log(param)
        type=param.slice(1,param.indexOf("="))
        id=param.slice(param.indexOf("=")+1)
        if(type=="patientId"){
            this.getBillByPatientId(id)
        }else if(type="doctorId"){

        }
    }
})